import { defineStore } from 'pinia'
import { getCarousels, getAllClubs, getPosts } from '@/service/home.js'

const useHomeStore = defineStore('home', {
	state: () => ({
		carouselList: [],
		clubsList: [],
		postsList: [],
		postsTotalCount: 0,
		clubsTotalCount: 0
	}),
	actions: {
		// 获取轮播图数据
		async getCarouselsAction() {
			const carouselListResult = await getCarousels()
			const { list } = carouselListResult.data
			this.carouselList = list
		},

		// 获取全部社团信息
		async getClubsListAction(limit = 5, offset = 0, status) {
			const clubsListResult = await getAllClubs(limit, offset, status)
			const { totalCount, list } = clubsListResult.data
			this.clubsList = list
			this.clubsTotalCount = totalCount
		},
		
		// 查询帖子
		async getPostsAction(queryInfo) {
		  const res = await getPosts(queryInfo)
		  const { list, totalCount } = res.data
		  this.postsList = list
		  this.postsTotalCount = totalCount
		},
	}
})

export default useHomeStore
